<?php if ( ! defined('DIR')) exit('No direct script access allowed');

	class mysql{
			
		private $conn;
		
		private static $_instance = null;
		
		//私有构造函数，防止直接创建对象
		public function __construct(){
		}
		
		//私有克隆函数，防止外办克隆对象
		private function __clone(){
		}
		
		public function conn($db = null , $username = null , $password = null){
			$this->conn = mysql_connect($db , $username , $password);
			if(!$this->conn){
				die('Could not connect: ' . mysql_error());
			}
		}
		
		static public function getInstance() {
			if(is_null(self::$_instance) || !isset(self::$_instance)) {
				self::$_instance = new self;
			}
			
			return self::$_instance;
		}
		
		public function choose_db($db_name){
			$db_selected = mysql_select_db($db_name , $this->conn);
			if(!$db_selected){
				die('Could not select database : '. $db_name . mysql_error());
			}
		}
		
		public function query($query){
				$result = mysql_query($query,$this->conn);
				if(!result){
					die('sql query error ' . mysql_error());
				}
				while($record = mysql_fetch_assoc($result)){
					$ret[] = $record;
				}
				return $ret;
		}
		
	}
	
?>